﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ref和out
{
    class ref和out作业
    {
        static void Main(string[] args)
        {
            int[] arr = new int[5];
            int max = 0;
            int min = 0;
            int sum = 0;
            int avg = 0;
            for (int i = 0; i < arr.Length; i++)
            {
                Console.WriteLine("请输入第{0}数", (i + 1));
                arr[i] = int.Parse(Console.ReadLine());
            }
            ref和out作业 pro = new ref和out作业();
            pro.Test01(arr, ref max, ref min, ref sum, ref avg);
            //pro.Test02(arr, out max, out min, out sum, out avg);
            Console.WriteLine("整数数组中的最大值为：{0}，最小值为：{1}，和为：{2}，平均数为：{3}", max, min, sum, avg);
            Console.ReadLine();
        }
        public void Test01(int[] arr, ref int max, ref int min, ref int sum, ref int avg)
        {
            min = arr[0];
            max = arr[0];
            foreach (int item1 in arr)
            {
                if (item1 <= min)
                {
                    min = item1;
                }
                if (item1 >= max)
                {
                    max = item1;
                }
            }
            foreach (int item2 in arr)
            {
                sum += item2;
            }
            avg = sum / 5;
        }
        public void Test02(int[] arr, out int max, out int min, out int sum, out int avg)
        {
            min = arr[0];
            max = arr[0];
            sum = 0;
            foreach (int item1 in arr)
            {
                if (item1 <= min)
                {
                    min = item1;
                }
                if (item1 >= max)
                {
                    max = item1;
                }
            }
            foreach (int item2 in arr)
            {
                sum += item2;
            }
            avg = sum / 5;
        }
        //ref 必须先赋值，out 可以不用，但是out在出方法前必须全部赋值。
    }
}
